package com.bw.lib_common.livedata_eventbus

import androidx.lifecycle.MutableLiveData

/**
 * @author ykj
 * @date 2025-10-16 20:40
 * @description
 */
object LiveDataEventBus {
    //所有的liveData
    private val bus = mutableMapOf<String,MutableLiveData<*>>()
    fun <T>with(key:String,type:Class<T>):MutableLiveData<T>{
        if(!bus.contains(key)){
            bus[key] = MutableLiveData<T>()
        }
        return bus[key] as MutableLiveData<T>
    }

    /**
     * 发送事件
     */
    fun <T>postEvent(key:String,value:T){
        with(key,value!!::class.java).value = value
    }
}